<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>Dynamic Table</title>

    <!--icheck-->
    <link href="/public/js/iCheck/skins/minimal/minimal.css" rel="stylesheet">
    <link href="/public/js/iCheck/skins/minimal/red.css" rel="stylesheet">
    <link href="/public/js/iCheck/skins/minimal/green.css" rel="stylesheet">
    <link href="/public/js/iCheck/skins/minimal/blue.css" rel="stylesheet">
    <link href="/public/js/iCheck/skins/minimal/yellow.css" rel="stylesheet">
    <link href="/public/js/iCheck/skins/minimal/purple.css" rel="stylesheet">

    <link href="/public/js/iCheck/skins/square/square.css" rel="stylesheet">
    <link href="/public/js/iCheck/skins/square/red.css" rel="stylesheet">
    <link href="/public/js/iCheck/skins/square/green.css" rel="stylesheet">
    <link href="/public/js/iCheck/skins/square/blue.css" rel="stylesheet">
    <link href="/public/js/iCheck/skins/square/yellow.css" rel="stylesheet">
    <link href="/public/js/iCheck/skins/square/purple.css" rel="stylesheet">

    <link href="/public/js/iCheck/skins/flat/grey.css" rel="stylesheet">
    <link href="/public/js/iCheck/skins/flat/red.css" rel="stylesheet">
    <link href="/public/js/iCheck/skins/flat/green.css" rel="stylesheet">
    <link href="/public/js/iCheck/skins/flat/blue.css" rel="stylesheet">
    <link href="/public/js/iCheck/skins/flat/yellow.css" rel="stylesheet">
    <link href="/public/js/iCheck/skins/flat/purple.css" rel="stylesheet">

    <link rel="stylesheet" type="text/css" href="/public/js/bootstrap-select-1.12.4/dist/css/bootstrap-select.css" />
    <style type="text/css">
        .p_supp_link {
            margin-bottom: 30px;
        }
        .sku_color,.sku_size {
            margin-top: 20px;
        }
    </style>

    <?php $this->load->view('library/header');?>
    <link rel="stylesheet" type="text/css" href="/public/js/bootstrap-table-master/dist/bootstrap-table.min.css" />
    <link rel="stylesheet" type="text/css" href="/public/js/bootstrap-table-master/dist/extensions/fixed-columns/bootstrap-table-fixed-columns.min.css" />
    <style type="text/css">
        .main-content {
            margin-left: 240px;
            background: #eff0f4;
            min-height: 680px;
        }
        .row {
            margin-left: -7px;
            margin-right: -7px;
        }
        .col-xs-1, .col-sm-1, .col-md-1, .col-lg-1, .col-xs-2, .col-sm-2, .col-md-2, .col-lg-2, .col-xs-3, .col-sm-3, .col-md-3, .col-lg-3, .col-xs-4, .col-sm-4, .col-md-4, .col-lg-4, .col-xs-5, .col-sm-5, .col-md-5, .col-lg-5, .col-xs-6, .col-sm-6, .col-md-6, .col-lg-6, .col-xs-7, .col-sm-7, .col-md-7, .col-lg-7, .col-xs-8, .col-sm-8, .col-md-8, .col-lg-8, .col-xs-9, .col-sm-9, .col-md-9, .col-lg-9, .col-xs-10, .col-sm-10, .col-md-10, .col-lg-10, .col-xs-11, .col-sm-11, .col-md-11, .col-lg-11, .col-xs-12, .col-sm-12, .col-md-12, .col-lg-12 {
            position: relative;
            min-height: 1px;
            padding-left: 7px;
            padding-right: 7px;
        }
        .form-horizontal .form-group {
            margin-left: -7px;
            margin-right: -7px;
        }
        .form-group {margin-bottom: 14px;}
        .icheck .checkbox, .icheck .radio {margin-bottom:0;}
        .btn-sm {padding: 7px 10px;}
        .goods_num p{margin-bottom: 8px;height: 18px; line-height: 18px; width: 220px;}
        .inventory_num p{margin-bottom: 8px;height: 18px; line-height: 18px; width: 100px;}
        .web {width: 130px; display: inline-block; float: left;}
        .order {padding-left: 10px; width: 90px; display: inline-block;
            float: left;}
        .bootstrap-table .fixed-table-container .table th, .bootstrap-table .fixed-table-container .table td {
            vertical-align: top;
            box-sizing: border-box;
        }
        #table p {
            line-height: 18px;
            height: 18px;
            margin-bottom: 5px;
            font-size: 13px;
        }
        .sale_count {
            width: 120px;
        }
    </style>
</head>

<body class="sticky-header">

<section>

    <?php $this->load->view('library/left');?>

    <!-- main content start-->
    <div class="main-content" >

        <?php $this->load->view('library/top');?>

        <!--body wrapper start-->
        <div class="wrapper">

            <section class="panel">
                <header class="panel-heading">
                    <div class="tools pull-left">
                        搜索
                    <div class="btn-group" id="drop_down">
                        <button data-toggle="dropdown" type="button" id="dropdown" data-id="3" class="btn btn-default btn-sm dropdown-toggle">
                            近3天销量 <span class="caret"></span>
                        </button>
                        <ul role="menu" class="dropdown-menu">
                            <li><a data-id="3" href="#">近3天销量</a></li>
                            <li><a data-id="7" href="#">近7天销量</a></li>
                            <li><a data-id="15" href="#">近15天销量</a></li>
                            <li class="divider"></li>
                            <li><a data-id="-1" href="#">全部销量</a></li>
                        </ul>
                    </div>
                    </div>
                    <span class="tools pull-right">
                        <a href="<?php echo base_url('Product/salegoods'); ?>" data-toggle="modal" class="btn btn-primary">旧版</a>
                        <a class="fa fa-chevron-up" href="javascript:;"></a>
                    </span>
                </header>
                <!--搜索选项框-->
                <div class="panel-body" style="display: none;">
                    <div class="padding-left">
                        <form class="form-horizontal bucket-form" method="get">
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="form-group ">
                                        <label class="col-sm-1 control-label">站点:</label>

                                        <div id="form_web" class="col-sm-11 slide-toggle">
                                            <div class="icheck minimal">
                                            <div class="checkbox single-row all_web_id">
                                                <input type="checkbox" <?php echo (count($param['web_id']) == count($se_arr['siteweb']) || count($param['web_id']) == 0) ? 'checked ' : '';?> value="<?php echo count($se_arr['siteweb']);?>"  >
                                                <label>全部</label>
                                            </div>
                                            <?php if ($param['web_id']): ?>
                                                <?php foreach ($se_arr['siteweb'] as $web_id => $siteweb):?>
                                                    <div class="checkbox single-row web_ids">
                                                        <input type="checkbox" name="web_id[]" <?php echo in_array($web_id, $param['web_id']) ? 'checked' : '';?> value="<?php echo $web_id;?>"  >
                                                        <label><?php echo $siteweb; ?></label>
                                                    </div>
                                                <?php endforeach;?>
                                            <?php else:?>
                                            <?php foreach ($se_arr['siteweb'] as $web_id => $siteweb):?>
                                                <div class="checkbox single-row web_ids">
                                                    <input type="checkbox" name="web_id[]" checked value="<?php echo $web_id;?>"  >
                                                    <label><?php echo $siteweb; ?></label>
                                                </div>
                                            <?php endforeach;?>
                                            <?php endif; ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">产品状态:</label>

                                        <div id="form_sale" class="col-sm-9 slide-toggle">
                                            <div class="icheck minimal">
                                                <div class="radio single-row">
                                                    <input tabindex="3" type="radio" <?php echo ($param['is_on_sale'] == 2 || !$param['is_on_sale']) ? 'checked' : '';?> name="is_on_sale" value="2">
                                                    <label>全部</label>
                                                </div>
                                                <div class="radio single-row">
                                                    <input tabindex="3" type="radio" <?php echo $param['is_on_sale'] == 1 ? 'checked' : '';?> name="is_on_sale" value="1">
                                                    <label>在售</label>
                                                </div>

                                                <div class="radio single-row">
                                                    <label class="disabled"><input name="is_on_sale" value="-1" <?php echo $param['is_on_sale'] == -1 ? 'checked' : '';?> type="radio" ></label>
                                                    <label>下架</label>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">分类:</label>
                                        <div id="form_cate" class="col-sm-10 icheck minimal">
                                            <div class="row">
                                                <div class="col-md-4">
                                                    <select name="cate_id[]" class="form-control col-sm-4 s_cate_id">
                                                        <option value="0">选择分类</option>
                                                        <?php foreach ($se_arr['cate'] as $cate_id => $cate): ?>
                                                            <option <?php echo $cate_id == $param['cate_id'][0] ? 'selected' : '' ?> value="<?php echo $cate_id;?>"><?php echo $cate['cate_name'];?></option>
                                                        <?php endforeach;?>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">开发员:</label>

                                        <div id="form_user" class="col-sm-9 icheck minimal">
                                            <select name="admin_id[]" data-live-search-placeholder="搜索供应商" data-live-search="true" class="aa form-control selectpicker s_supp_id">
                                                <option value="0">选择开发员</option>
                                                <?php foreach ($se_arr['admin'] as $admin_id => $admin):?>
                                                    <option value="<?php echo $admin_id; ?>" <?php echo $param['admin_id'] == $admin_id ? 'selected' : '';?>><?php echo $admin; ?></option>
                                                <?php endforeach;?>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">货号:</label>

                                        <div id="from_goods_sn" class="col-sm-9 minimal">
                                            <input name="goods_sn" value="<?php echo implode(' ', $param['goods_sn']);?>"  class="form-control" />
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">供应商:</label>

                                        <div id="from_supp" class="col-sm-9 icheck minimal">
                                            <select name="suppliers_id[]" data-live-search-placeholder="搜索供应商" data-live-search="true" class="aa form-control selectpicker s_supp_id">
                                                <option value="0">选择供应商</option>
                                                <?php foreach ($se_arr['supp'] as $supp_id => $supp): ?>
                                                    <option <?php echo $param['suppliers_id'] == $supp_id ? 'selected' : '';?> value="<?php echo $supp_id;?>"><?php echo $supp;?></option>
                                                <?php endforeach;?>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row" id="ext_search">
                              <div class="col-md-4">
                                <div class="form-group">
                                  <label class="col-sm-3 control-label">浏览量:</label>
                                  <div class="col-sm-9 icheck minimal">
                                    <div class="input-group input-large">
                                      <input type="text" value="" class="form-control ll_from" name="ll_from">
                                      <span class="input-group-addon">To</span>
                                      <input type="text" value="" class="form-control ll_to" name="ll_to">
                                    </div>
                                  </div>
                                </div>
                              </div>

                              <div class="col-md-4">
                                <div class="form-group">
                                  <label class="col-sm-3 control-label">加车率(%):</label>
                                  <div class="col-sm-9 icheck minimal">
                                    <div class="input-group input-large">
                                      <input type="text" value="" class="form-control jc_from" name="jc_from">
                                      <span class="input-group-addon">To</span>
                                      <input type="text" value="" class="form-control jc_to" name="jc_to">
                                    </div>
                                  </div>
                                </div>
                              </div>

                              <div class="col-md-4">
                                <div class="form-group">
                                  <label class="col-sm-3 control-label">转化率(%):</label>
                                  <div class="col-sm-9 icheck minimal">
                                    <div class="input-group input-large">
                                      <input type="text" value="" class="form-control zh_from" name="zh_from">
                                      <span class="input-group-addon">To</span>
                                      <input type="text" value="" class="form-control zh_to" name="zh_to">
                                    </div>
                                  </div>
                                </div>
                              </div>

                            </div>

                            <div class="row">
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">上架时间:</label>

                                        <div id="form_on" class="col-sm-9 icheck minimal">
                                            <div class="input-group input-large custom-date-range" data-date="13/07/2013" data-date-format="mm/dd/yyyy">
                                                <input type="text" value="<?php echo $param['on_sale_time'][0]; ?>" class="form-control on1" name="from">
                                                <span class="input-group-addon">To</span>
                                                <input type="text" value="<?php echo $param['on_sale_time'][1];?>" class="form-control on2" name="to">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">统计时间:</label>
                                        <div class="col-sm-4 btn-group" >
                                            <button class="btn btn-default btn-sm" type="button">近7天</button>
                                            <button class="btn btn-default btn-sm" type="button">近1月</button>
                                            <button class="btn btn-default btn-sm" type="button">本月内</button>
                                        </div>
                                        <div id="form_statistical" class="col-sm-6 icheck minimal">
                                            <div class="input-group input-large custom-date-range" data-date="13/07/2013" data-date-format="mm/dd/yyyy">
                                                <input type="text" value="<?php echo $param['statistical_time'][0]; ?>" class="form-control on1" name="from">
                                                <span class="input-group-addon">To</span>
                                                <input type="text" value="<?php echo $param['statistical_time'][1]; ?>" class="form-control on2" name="to">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-1">
                                    <button type="submit" class="btn btn-info">搜索</button>
                                </div>
                            </div>

                        </form>
                    </div>
                </div>
            </section>

            <!--表-->
            <section class="panel">
                <div class="panel-body overflow-x">
                    <section id="flip-scroll">
                        <table id="table">
                        </table>
                        <div class="dataTables_paginate paging_bootstrap pagination" style="margin: 0;"><ul><?php echo $pages; ?></ul></div>
                    </section>
                </div>
            </section>



        </div>
        <!--body wrapper end-->

        <!--footer section start-->
        <footer>
            2014 &copy; AdminEx by
        </footer>
        <!--footer section end-->


    </div>
    <!-- main content end-->
</section>

<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal-g" class="modal fade ex-modal-lg">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">Form Tittle</h4>
            </div>
            <div class="modal-body">

            </div>

        </div>
    </div>
</div>
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade ex-modal-lg">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">Form Tittle</h4>
            </div>
            <div class="modal-body">
                <canvas id="canvas"></canvas>
            </div>

        </div>
    </div>
</div>
<?php $this->load->view('library/footer');?>
<script src="/public/js/bootstrap-table-master/dist/bootstrap-table.js"></script>
<script src="/public/js/bootstrap-table-master/dist/extensions/fixed-columns/bootstrap-table-fixed-columns.min.js"></script>
<!--ios7-->
<script src="/public/js/ios-switch/switchery.js" ></script>
<script src="/public/js/ios-switch/ios-init.js" ></script>
<!--icheck -->
<script src="/public/js/iCheck/jquery.icheck.js"></script>
<script src="/public/js/icheck-init.js"></script>

<script src="/public/js/Chart.min.js"></script>
<script src="/public/js/utils.js"></script>

<script src="/public/js/bootstrap-select-1.12.4/dist/js/bootstrap-select.min.js"></script>
<script src="/public/js/scripts.js"></script>
<script type="text/javascript">

    $('.selectpicker').selectpicker({
        size: 6
    });

    $(function () {

        $.fn.scrollUnique = function() {
            return $(this).each(function() {
                var eventType = 'mousewheel';
                if (document.mozHidden !== undefined) {
                    eventType = 'DOMMouseScroll';
                }

                $(this).on(eventType, function(event) {
                    // 一些数据
                    var scrollTop = this.scrollTop,
                        scrollHeight = this.scrollHeight,
                        height = this.clientHeight;

                    var delta = (event.originalEvent.wheelDelta) ? event.originalEvent.wheelDelta : -(event.originalEvent.detail || 0);

                    if ((delta > 0 && scrollTop <= delta) || (delta < 0 && scrollHeight - height - scrollTop <= -1 * delta)) {
                        // IE浏览器下滚动会跨越边界直接影响父级滚动，因此，临界时候手动边界滚动定位
                        this.scrollTop = delta > 0? 0: scrollHeight;
                        // 向上滚 || 向下滚
                        event.stopPropagation();
                    }
                });
            });
        };

        $('#table').scrollUnique();

        $('#table').on('click', '.country_num_all', function () {
            $(this).popover({
                'html': true,
                'content': function () {
                    return $(this).next('.country_all').html();
                }
            });
        });

        var $table = $('#table');
        var columns = [
            {
                field:'open'
            },
            {
                field:'goods_id',
                title:'编号'
            },
            {
                field:'original_img',
                title:'图片'
            },{
                field:'goods_info',
                title:'产品信息'
            },{
                field:'purchase_info',
                title:'供应商信息'
            },{
                field:'on_sale_info',
                title:'上架状态'
            },{
                field:'data_info',
                title:'数据项目'
            },{
                field:'all_day',
                title:'总累计'
            },{
                field:'3_day',
                title:'近3天'
            },{
                field:'7_day',
                title:'近7天'
            },{
                field:'30_day',
                title:'近30天'
            },{
                field:'tom_day',
                title:'本月累计'
            }
        ];
        var of_title = ['all_day','3_day','7_day','30_day','tom_day'];
        <?php if ($ga_goods['title_list']):?>
            var title_list = <?php echo json_encode($ga_goods['title_list']);?>;
            for (x in title_list) {
                if (of_title.indexOf(x) == -1) {
                    columns.push({field:x, title:title_list[x]});
                }
            }
        <?php endif;?>

        columns.push({
          field: 'country_order',
          title: '各国家销量'
        }, {
          field: 'inventory_info',
          title: '仓储信息'
        }, {
          field: 'sales_info',
          title: '销售趋势'
        })




        $table.bootstrapTable({
            sidePagination: "server",
            fixedColumns: true,
            columns: [columns],
            fixedNumber: 3,
            data: <?php echo $goods_list; ?>
        });


        var form = [];
        var page = 1;

        var goods_inventory = [];
        ajax_goods();

        function ajax_goods(goods_ids) {
            var goods_ids = goods_ids ? goods_ids : '<?php echo $goods_ids;?>';
            $.get("<?php echo base_url("SalesCount/siteweb_goods_sale/goods_ids/");?>"+goods_ids, function (data) {

                var tr = 0;
                for (x in data) {
                    var html = '<div class="goods_num">';
                    var i = 1;
                    for (j in data[x]) {
                        html += '<p><span class="web"><span class="web-name">' + data[x][j].web_name + ': </span><span class="day">' + data[x][j].day + '天</span></span>' +
                            '<span class="order">累销: ' + parseInt(data[x][j].order_num) + ' </span></p>';
                        if (i >= 4) {
                            break;
                        }
                        i++;
                    }
                    html += '</div><a href="#myModal" data-toggle="modal" class="btn btn-info btn-xs ajax-but" data-id="' + x.replace(/\s+/g,"") + '">查看走势图</a>';

                    $table.bootstrapTable('updateCell',{index: tr,field:'on_sale_info', value:html});
                    tr++;
                    //$('.goods-' + x).html(html);
                }
                $table.bootstrapTable('resetView');
            }, 'json');


            country_web_id = '';
            $('#form_web  .web_ids input:checked').each(function (i) {
                country_web_id += i == 0 ? $(this).val() : '_' + $(this).val();
            });
            $.get("<?php echo base_url("SalesCount/ajax_country_order/goods_ids/");?>"+goods_ids+'/web_ids/'+country_web_id, function (data) {

                var tr = 0;
                for (x in data) {
                    var html = '<div class="country_num">';
                    var html_op = '<div class="country_all" style=" display: none;">';
                    var i = 1;
                    for (j in data[x]) {

                        if (i <= 4) {
                            html += '<p><span class="web"><span class="country-order">' + data[x][j].country + ': ' + parseInt(data[x][j].goods_number) + ' </span></p>';
                        }

                        html_op += '<p><span class="web"><span class="country-order">' + data[x][j].country + ': ' + parseInt(data[x][j].goods_number) + ' </span></p>';

                        i++;
                    }

                    html_op += '</div>';

                    html += '</div><a class="btn btn-info btn-xs country_num_all" data-id="' + x.replace(/\s+/g,"") + '">所有国家</a>' + html_op;

                    $table.bootstrapTable('updateCell',{index: tr,field:'country_order', value:html});
                    tr++;
                    //$('.goods-' + x).html(html);
                }
                $table.bootstrapTable('resetView');
            }, 'json');

            $.get("<?php echo base_url("SalesCount/product_inventory/goods_ids/");?>"+goods_ids, function (data) {
                var tr = 0;
                goods_inventory = data;
                for (x in data) {
                    var tr_tabel = $table.bootstrapTable('getRowByIndex', tr);
                    var html = '<div class="inventory_num">';
                    var Sellable = 0;
                    var noStock = 0;
                    var purchaseOnway = 0;
                    var pending = 0;
                    var inventoryCost = 0;
                    for (j in data[x]) {
                        if (data[x][j] != null) {
                            Sellable += parseInt(data[x][j].Sellable);
                            noStock += parseInt(data[x][j].noStock);
                            pending += parseInt(data[x][j].pending);
                            purchaseOnway += parseInt(data[x][j].purchaseOnway);
                            inventoryCost += parseFloat(data[x][j].inventoryCost);
                        }
                    }
                    html += '<p>可售: ' + Sellable + '</p>';
                    html += '<p>采购在途：<a class="ajax-zaitu" data-toggle="modal" data-id="' + x.replace(/\s+/g,"") + '" href="#myModal-g">' + purchaseOnway + '</a></p>';
                    html += '<p>待上架：' + pending + '</p>';
                    html += '<p>缺货: ' + noStock + '</p>';
                    html += '</div>';

                    var sale_html = tr_tabel.sales_info;
                    sale_html += '<p>库存：'+inventoryCost.toFixed(2)+ '</p>';

                    $table.bootstrapTable('updateCell',{index: tr,field:'inventory_info', value:html});
                    $table.bootstrapTable('updateCell',{index: tr,field:'sales_info', value:sale_html});
                    tr++;
                }

                $table.bootstrapTable('resetView');
            }, 'json');
        }

        function web_url()
        {
            var form_web = [];
            form = [];

            form_web['web_id'] = '';
            $('#form_web  .web_ids input:checked').each(function (i) {
                form_web['web_id'] += i == 0 ? $(this).val() : '_' + $(this).val();
            });

            form_web['sale_count'] = $('#dropdown').attr('data-id');
            form_web['is_on_sale'] = $('#form_sale input:checked').val();

            form_web['cate_id'] = '';
            $('#form_cate select').each(function (i) {
                form_web['cate_id'] += i == 0 ? $(this).val() : '_' + $(this).val();
            });

            form_web['admin_id'] = $('#form_user select').val();
            form_web['goods_sn'] = $('#from_goods_sn input').val();
            form_web['suppliers_id'] = $('#from_supp select').val();
            if ($('#form_on .on1').val() != undefined && $('#form_on .on2').val() != undefined) {
                form_web['on_sale_time'] = $('#form_on .on1').val() + '_' + $('#form_on .on2').val();
            }

            if ($('#form_statistical .on1').val() != undefined && $('#form_statistical .on2').val() != undefined) {
                form_web['statistical_time'] = $('#form_statistical .on1').val() + '_' + $('#form_statistical .on2').val();
            }

            if ($('#ext_search .ll_from').val() != undefined && $('#ext_search .ll_to').val() != undefined) {
                form_web['ll_info'] = $('#ext_search .ll_from').val() + '_' + $('#ext_search .ll_to').val();
            }

            if ($('#ext_search .jc_from').val() != undefined && $('#ext_search .jc_to').val() != undefined) {
                form_web['jc_info'] = $('#ext_search .jc_from').val() + '_' + $('#ext_search .jc_to').val();
            }

            if ($('#ext_search .zh_from').val() != undefined && $('#ext_search .zh_to').val() != undefined) {
                form_web['zh_info'] = $('#ext_search .zh_from').val() + '_' + $('#ext_search .zh_to').val();
            }

            // console.log(form_web)
            var i = 0;
            for (x in form_web) {
                if (form_web[x] && form_web[x] != '_' && form_web[x] != 0) {
                    form[i] = x + '/' + form_web[x];
                    i++;
                }
            }
        }

        $('.form-horizontal').submit(function () {

            web_url();

            //window.location.href = '<?php echo base_url('SalesCount/index/page/1/');?>' + form.join('/');

            $.get('<?php echo base_url('SalesCount/ajax_goods_list/');?>' + form.join('/') + '/page/1', function (data) {
                columns = [
                    {
                        field:'open'
                    },
                    {
                        field:'goods_id',
                        title:'编号'
                    },
                    {
                        field:'original_img',
                        title:'图片'
                    },{
                        field:'goods_info',
                        title:'产品信息'
                    },{
                        field:'purchase_info',
                        title:'供应商信息'
                    },{
                        field:'on_sale_info',
                        title:'上架状态'
                    }, {
                        field:'data_info',
                        title:'数据项目'
                    },{
                        field:'all_day',
                        title:'总累计'
                    },{
                        field:'3_day',
                        title:'近3天'
                    },{
                        field:'7_day',
                        title:'近7天'
                    },{
                        field:'30_day',
                        title:'近30天'
                    },{
                        field:'tom_day',
                        title:'本月累计'
                    }
                ];
                var title_list = data.ga_goods.title_list;
                for (x in title_list) {
                    if (of_title.indexOf(x) == -1) {
                        columns.push({field:x, title:title_list[x]});
                    }
                }

                columns.push({
                  field: 'country_order',
                  title: '各国家销量'
                }, {
                  field: 'inventory_info',
                  title: '仓储信息'
                }, {
                  field: 'sales_info',
                  title: '销售趋势'
                })


                $("#table").bootstrapTable('destroy');
                $("#table").bootstrapTable({
                    sidePagination: "server",
                    columns:[columns],
                    fixedColumns: true,
                    fixedNumber: 3,
                    data: data.rows
                });
                ajax_goods(data.goods_ids);
                $('.pagination ul').html(data.pages);

            },'json');
            $table.bootstrapTable('resetView');
            return false;
        });

        $('#drop_down a').click(function () {

            var sale_count = parseInt($(this).attr('data-id'));
            var sale_html = $(this).html();

            $('#dropdown').html(sale_html).attr('data-id', sale_count);


            web_url();

            $.get('<?php echo base_url('SalesCount/ajax_goods_list/');?>' + form.join('/') + '/page/1', function (data) {
                $("#table").bootstrapTable('destroy');
                $("#table").bootstrapTable({
                    sidePagination: "server",
                    columns:[columns],
                    fixedColumns: true,
                    fixedNumber: 3,
                    data: data.rows
                });
                ajax_goods(data.goods_ids);
                $('.pagination ul').html(data.pages);

            },'json');
            $table.bootstrapTable('resetView');
            return false;
        });

        $('#table').on('click', '.detail-close', function () {
            var count = parseInt($(this).attr('data-count'));
            var d_index = parseInt($(this).parents('tr').attr('data-index'));
            var goods_id = $(this).attr('goods_id');
            var goods_count = count + d_index;
            for (var i=d_index+1;i <= goods_count;i++) {
                $table.bootstrapTable('hideRow', {
                    index: i
                });
            }
            $table.bootstrapTable('updateCell',{index: d_index,field:'open', value:'<img class="detail-open" data-id="'+ goods_id +'" data-count="' + count + '" src="/public/images/details_open.png" />'});
        });

        $('#table').on('click', '.detail-open', function () {

            var d_index = $(this).parents('tr').attr('data-index');
            var goods_id = $(this).attr('data-id');
            var count = $(this).attr('data-count');

            if (count > 0) {
                $table.bootstrapTable('updateCell',{index: d_index,field:'open', value:'<img class="detail-close" data-id="'+ goods_id +'" data-count="' + count + '" src="/public/images/details_close.png" />'});
                var goods_count = count + d_index + 1;
                for (var i=d_index;i < goods_count;i++) {
                    $table.bootstrapTable('showRow', {
                        index: i
                    });
                }
                return false;
            }

            $.get('<?php echo base_url('/SalesCount/ajax_sku_list');?>/goods_id/'+goods_id, function (data) {
                var inventory = goods_inventory[' '+goods_id];
                $table.bootstrapTable('updateCell',{index: d_index,field:'open', value:'<img class="detail-close" data-id="'+ goods_id +'" data-count="' + Object.keys(data).length + '" src="/public/images/details_close.png" />'});
                for (x in data) {

                    var html_web_goods_number = '<div class="goods_num">';

                    for (j in data[x].item) {
                        html_web_goods_number += '<p><span class="web"><span class="web-name">' + j + ': </span><span class="day">-</span></span><span class="order">累销: ' + data[x].item[j].goods_number + '</span></p>';
                    }
                    html_web_goods_number += '</div>';

                    var Sellable_inventory = 0;
                    var noStock_inventory = 0;
                    var purchaseOnway_inventory = 0;
                    var pending_inventory = 0;
                    var inventoryCost_inventory = 0;
                    for (iv in data[x].size) {
                        if (inventory[iv]) {
                            Sellable_inventory += parseInt(inventory[iv].Sellable);
                            noStock_inventory += parseInt(inventory[iv].noStock);
                            purchaseOnway_inventory += parseInt(inventory[iv].purchaseOnway);
                            pending_inventory += parseInt(inventory[iv].pending);
                            inventoryCost_inventory += parseFloat(inventory[iv].inventoryCost);
                        }
                    }

                    var html_inventory_info = '<div class="inventory_num"><p>可售：'+
                        Sellable_inventory +'</p><p>采购在途：'+
                        purchaseOnway_inventory +'</p><p>待上架：'+
                        pending_inventory +'</p><p>缺货：'+ noStock_inventory +'</p>';

                    var tabe_row = {
                        'goods_id': '<img class="detail-color-open" data-id="' + goods_id + '-' + x + '" src="/public/images/details_open.png" />',
                        'original_img': x,
                        'sales_info' : '<p>销售额: '+data[x].goods_num_price.toFixed(2)+'</p><p>库存：'+ inventoryCost_inventory.toFixed(2) +'</p>',
                        'on_sale_info': html_web_goods_number,
                        'data_info' : '<p>浏览量</p><p>加车率</p><p>转化率</p><p>销量</p>',
                        'inventory_info': html_inventory_info
                    };

                    for (s in data[x].date) {

                        var date_adds_cart = data[x].date[s].adds_cart / data[x].date[s].detail_views * 100;
                        var date_item_quantity = data[x].date[s].item_quantity / data[x].date[s].detail_views * 100;

                        tabe_row[s] = '<p>'+ data[x].date[s].detail_views +'</p><p>' + date_adds_cart.toFixed(2) + '%</p><p>' + date_item_quantity.toFixed(2) + '%</p><p>'+ data[x].date[s].item_quantity +'</p>';
                    }

                    $table.bootstrapTable('insertRow', {
                        index:parseInt(d_index)+1,
                        row:tabe_row});
                }
            }, 'json');

        });

        $('#table').on('click', '.detail-color-open', function () {

            var d_index = $(this).parents('tr').attr('data-index');
            var goods_id = $(this).attr('data-id');

            $table.bootstrapTable('updateCell',{index: d_index,field:'goods_id', value:'<img class="detail-close" data-id="' + goods_id + '" src="/public/images/details_close.png" />'});


        });


        $('.all_web_id input').on('ifChecked', function(event){
            $('.web_ids input').iCheck('check');
        });

        $('.all_web_id input').on('ifUnchecked', function(event){
            $('.web_ids input').iCheck('uncheck');
        });

        $('.pagination').on('click', 'a', function () {

            page = $(this).attr('data-ci-pagination-page');

            $.get('<?php echo base_url('SalesCount/ajax_goods_list/');?>/' + form.join('/') + '/page/' + page, function (data) {
                $("#table").bootstrapTable('destroy');
                $("#table").bootstrapTable({
                    sidePagination: "server",
                    columns:[columns],
                    fixedColumns: true,
                    fixedNumber: 3,
                    data: data.rows
                });
                ajax_goods(data.goods_ids);
                $('.pagination ul').html(data.pages);

            },'json');

            return false;
        });

        /*table.rows().every( function () {
            this.child( 'Row details for row: '+this.index() );

        } ).draw();*/


        $('#example tbody').on( 'click', 'tr', function () {
            if ($(this).hasClass('selected')) {
                $(this).removeClass('selected');
            }
            else {
                table.$('tr.selected').removeClass('selected');
                $(this).addClass('selected');
            }
        } );

        $('#table').on('click', '.ajax-but', function () {
            var goods_id = $(this).attr('data-id');
            $('#myModal .modal-body').html('<canvas id="canvas"></canvas>');
            var jsonData = $.ajax({
                url: '<?php echo base_url('SalesCount/graph_ga_data/goods_id/'); ?>'+goods_id,
                dataType: 'json',
            }).done(function (results) {
                var lineChartData = {
                    labels: results.labels,
                    datasets: results.datasets
                };
                var ctx = document.getElementById('canvas').getContext('2d');
                window.myLine = Chart.Line(ctx, {
                    data: lineChartData,
                    options: {
                        responsive: true,
                        hoverMode: 'index',
                        stacked: false,
                        scales: {
                            yAxes: results.yAxes,
                        }
                    }
                });
            });

        });

        var cate = <?php echo json_encode($se_arr['cate']);?>;

        var item = [];

        function tree(items, deep) {
            for (x in items) {
                if (x == deep) {
                    item = items[x].item;
                    return true;
                } else {
                    tree(items[x].item, deep);
                }
            }
        }

        var param_cate = <?php echo json_encode($param['cate_id']); ?>

        for (c in param_cate) {
            tree(cate, param_cate[c]);
            if (item) {
                console.log(item);
                var html = '<div class="col-md-4 cate_select"><select name="cate_id[]" class="form-control col-sm-4 s_cate_id"><option value="0">请选择分类</option>';
                for (x in item) {
                    html += '<option ' + ( param_cate.indexOf(item[x].cate_id) > -1 ? 'selected' : '') + ' value="' + item[x].cate_id + '">' + item[x].cate_name + '</option>';
                }
                html += '</select></div>';
                $('#form_cate .row').append(html);
            }
        }


        $('body').on('change', '#form_cate select', function () {
            var cate_id = $(this).val();

            tree(cate, cate_id);
            if (item) {
                var html = '<div class="col-md-4 cate_select"><select name="cate_id[]" class="form-control col-sm-4 s_cate_id"><option value="0">请选择分类</option>';
                for (x in item) {
                    html += '<option ' + ( param_cate.indexOf(item[x].cate_id) > -1 ? 'selected' : '') + ' value="' + item[x].cate_id + '">' + item[x].cate_name + '</option>';
                }
                html += '</select></div>';
            }

            $(this).parent().nextAll('.cate_select').remove();
            $('#form_cate .row').append(html);

        });

        $("body").on("click", ".ajax-zaitu", function () {
            var id = $(this).attr('data-id');

            $.get('<?php echo base_url("SalesCount/purchase_orders/goods_id/");?>'+id, function (data) {
                html = '<table class="table table-bordered"><thead><tr><th>采购单号</th><th>供应商</th><th>SKU号</th><th>发起时间</th><th>累计天数</th><th>下单件数</th><th>已入</th><th>未入</th></tr></thead><tbody>';
                var expected = 0;
                var receving = 0;
                var not_into = 0;
                for (x in data) {
                    var i = 1;
                    for (j in data[x].detail) {

                        if (i == 1) {
                            html += '<tr>' +
                                '<td>' + data[x].po_code + '</td>' +
                                '<td>' + data[x].supplier_name + '</td>' +
                                '<td>' + j + '</td>' +
                                '<td>' + data[x].date_create + '</td>' +
                                '<td>' + data[x].day + '</td>' +
                                '<td>' + data[x].detail[j].qty_expected + '</td>' +
                                '<td>' + data[x].detail[j].qty_receving + '</td>' +
                                '<td>' + (data[x].detail[j].qty_expected - data[x].detail[j].qty_receving) + '</td>' +
                                '</tr>';
                        } else {
                            html += '<tr>' +
                                '<td></td>' +
                                '<td>' + data[x].supplier_name + '</td>' +
                                '<td>' + j + '</td>' +
                                '<td>' + data[x].date_create + '</td>' +
                                '<td>' + data[x].day + '</td>' +
                                '<td>' + data[x].detail[j].qty_expected + '</td>' +
                                '<td>' + data[x].detail[j].qty_receving + '</td>' +
                                '<td>' + (data[x].detail[j].qty_expected - data[x].detail[j].qty_receving) + '</td>' +
                                '</tr>';
                        }

                        expected += data[x].detail[j].qty_expected;
                        receving += data[x].detail[j].qty_receving;
                        not_into += data[x].detail[j].qty_expected > data[x].detail[j].qty_receving ? (data[x].detail[j].qty_expected - data[x].detail[j].qty_receving) : 0;
                        i++;
                    }
                }
                html += '<tr>' +
                    '<td>合计</td>' +
                    '<td></td>' +
                    '<td></td>' +
                    '<td></td>' +
                    '<td></td>' +
                    '<td>' + expected + '</td>' +
                    '<td>' + receving + '</td>' +
                    '<td>' + not_into + '</td>' +
                    '</tr>';
                html += '</tbody></table>';
                $('#myModal-g .modal-body').html(html);
                $('#myModal-g').modal();
            },'json');

            return false;
        });
    });

    $('.input-type-multiple').on('click', function () {

        var url = $(this).attr('href');

        var sn = $(this).attr('data-no');

        swal({
            title: '库存校正 - ' + sn,
            html:
            '<input id="sku_number" placeholder="输入库存" class="swal2-input">' +
            '<input id="log_info" placeholder="输入原因" class="swal2-input">',
            showCancelButton: true,
            confirmButtonText: 'Submit',
            showLoaderOnConfirm: true,
            preConfirm: function preConfirm() {
                return $.post(url, {sku_number: $('#sku_number').val(), log_info: $('#log_info').val()}, function (data) {
                    return data;
                },'json');
            },
            allowOutsideClick: false
        }).then(function (result) {
            console.log(result);
            if (result.value) {
                var data = result.value;
                swal({
                    type: data.status,
                    title: data.info
                }).then(function(isConfirm) {
                    location.reload();
                });
            }
        });
        return false;
    });

    $('.a-ajax').click(function () {

        var url = $(this).attr('href');
        swal({
            title: '确定要删除吗?',
            type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes, delete it!'
        }).then(function (result) {
            if (result.value) {
                $.get(url, {is_ajax: 1}, function (data) {
                    swal({
                        title: data.info,
                        text: '2秒后关闭',
                        type: data.status,
                        allowOutsideClick: false,
                        timer: data.stop ? data.stop : 1500,
                        showConfirmButton: false
                    }).then(function(isConfirm) {
                        location.reload();
                    });

                }, 'json');
            }
        })


        return false;
    });

</script>

<!--common scripts for all pages-->

</body>
</html>
